<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<script src="../js/jquery-1.6.2.min.js"></script>
		<style>
			.ui-page-login,
			body {
				width: 100%;
				height: 100%;
				margin: 0px;
				padding: 0px;
			}
			
			.mui-input-group:first-child {
				margin-top: 10px;
			}
			
			.mui-input-group label {
				width: 26%;
				margin-left: 6px;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 70%;
			}
			
			.mui-content-padded {
				margin-top: 25px;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
			
			.spliter {
				color: #bbb;
				padding: 0px 8px;
			}
			
			.oauth-area {
				position: absolute;
				bottom: 20px;
				left: 0px;
				text-align: center;
				width: 100%;
				padding: 0px;
				margin: 0px;
			}
			
			.oauth-area .oauth-btn {
				display: inline-block;
				width: 50px;
				height: 50px;
				background-size: 30px 30px;
				background-position: center center;
				background-repeat: no-repeat;
				margin: 0px 20px;
				/*-webkit-filter: grayscale(100%); */
				border: solid 1px #ddd;
				border-radius: 25px;
			}
			
			.oauth-area .oauth-btn:active {
				border: solid 1px #aaa;
			}
			
			.oauth-area .oauth-btn.disabled {
				background-color: #ddd;
			}
		</style>

	</head>

	<body>
		<div class="mui-content"  >
		<header class="mui-bar mui-bar-nav" style="height: 55px;">
			<img class="mui-title" src="../images/logo.png" style="margin: auto;width: 10%; margin-top: 15px;"></img>
		</header>
		<div class="mui-content">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-content-padded">
						<div class="link-area">
							<a style="color: #000000;">密码登录</a>
							<span class="spliter">|</span>
							<a id="ident" href="login_code.html">验证码登录</a>
						</div>
					</div>
				</div>

				<div class="mui-content">
					<form id='login-form2' class="mui-input-group">
						<div class="mui-input-row">
							<label>手机号</label>
							<input id='phonenumber' type="text" class=" mui-input" placeholder="请输入手机号" maxlength="11">
						</div>
						<div class="mui-input-row ">
							<label>密码</label>
							<input id='password' type="password" class="mui-input-password" placeholder="请输入密码">
						</div>
					</form>
					<div class="mui-content-padded">
						<button id='login' class="mui-btn mui-btn-block mui-btn-primary" onclick="checkIt()">登录</button>
						<div class="link-area">
							<a id='reg' href="reg.html">注册账号</a> <span class="spliter">|</span>
							<a id='forgetPassword' href="forget_password.html">忘记密码</a>
						</div>
					</div>
					<div class="mui-content-padded oauth-area">

					</div>
				</div>
				<script src="../js/mui.min.js"></script>
				<script src="../js/urlconfiguration.js"></script>
				<script language="javascript" type="text/javascript">
					//自动登录
					(function($, doc) {
						$.init();
						$.plusReady(function() {
							var users = JSON.parse(localStorage.getItem('$users'));
							if(users != null) {
								console.log("user:" + users.password);
								users.password = 123123;
								localStorage.setItem('$users', JSON.stringify(users));
								trace("初始化方法进入");
							}

							function trace(obj) {
								console.log(obj);
								var w = plus.webview.open("../main_page/nav.html"); //打开新的页面
								var t = plus.webview.currentWebview().close(); //关闭之前打开的页面
							}
						});
					})(mui, document);

					$("#phonenumber").blur(function() {
						var regphone = /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8])|(19[7]))\d{8}$/;
						var uphone = $("#phonenumber").val();
						$("#phonenumber").css("background-color", "white");
						if(uphone.length <= 0 || !regphone.test(uphone)) {
							mui.alert("手机号错误！");
						}
					});
					$("#password").blur(function() {
						var upassword = $("#password").val();
						$("#password").css("background-color", "white");
						if(upassword.length < 6 || upassword.length > 12) {
							mui.alert("密码为6到12位！");
						}
					});

					function Waiting() {
						var w = plus.nativeUI.showWaiting("正在加载...\n");
						w.onclose = function() {
							clearInterval(t);
						}
						var n = 3;
						var t = setInterval(function() {
							n--;
							w.setTitle("处理中，请等待5...\n" + n);
							if(n <= 0) {
								w.close();
								clearInterval(t);
							}
						}, 1000);
					}

					function checkIt() {
						//获取文本框的值    
						var account1 = document.getElementById("phonenumber").value;
						var account2 = document.getElementById("password").value;
						var regphone = /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8])|(19[7]))\d{8}$/;
						if(account1.length <= 0 || !regphone.test(account1)) {
							mui.alert("手机号格式错误！");
							return;
						}
						if(account2.length < 6 || account2.length > 12) {
							mui.alert("密码格式错误！");
							return;
						}
						var w = plus.nativeUI.showWaiting("正在加载...\n");
						//						获取手机序列号
						var clientid = plus.push.getClientInfo().clientid
						if(plus.os.name == 'iOS') {
							var token = plus.push.getClientInfo().token
						}
						$.ajax({
							contentType: "application/json",
							type: "GET",
							url: url_1 + "get_newUser.do?jsoncallback=?",
							data: "clientid=" + clientid + "&token=" + token + "&phone=" + account1 + "&password=" + account2,
							dataType: "json",
							success: function(data) {
								if(data.flag == 1) {
									var user_id = data.user.id;
									var users = {
										phonenumber: account1,
										password: account2
									};
									localStorage.setItem('$users', JSON.stringify(users));
									localStorage.setItem("user_id", user_id);
									localStorage.setItem("address_company", data.user.address_company);
									localStorage.setItem("address_home", data.user.address_home);
									localStorage.setItem("wechat", data.user.wechat);
									localStorage.setItem("name_company", data.user.name_company);
									localStorage.setItem("sex", data.user.sex);
									localStorage.setItem("phone", data.user.phone);
									localStorage.setItem("beans", data.user.beans);
									localStorage.setItem("name", data.user.name);
									localStorage.setItem("is_vip", data.user.is_vip);
									localStorage.setItem("user_authenticPer", data.user.user_authenticPer);
									localStorage.setItem("user_authenticCom", data.user.user_authenticCom);
									localStorage.setItem("avgscore_boss", data.user.avgscore_boss);
									localStorage.setItem("avgscore_worker", data.user.avgscore_worker);
									localStorage.setItem("headPortrait_url", data.user.headPortrait_url);
									if(data.user.skills != null) {
										var skills = "";
										for(i = 0; i < data.user.skills.length; i++) {
											skills += data.user.skills[i].name + "/";
										}
										localStorage.setItem("skills", skills);
									}
									w.close();
									window.location.href = "../main_page/nav.html";
								}
								if(data.flag == 2) {
									w.close();
									mui.alert("密码错误！");
								}
								if(data.flag == 3) {
									w.close();
									mui.alert("该手机号未被注册！！");
								}
							},
							error: function() {
								w.close();
								alert("网络连接出错！");
							}
						});
					}
				</script>
	</body>

</html>